//
//  String-Extension.swift
//  正则体验
//
//  Created by zhanglongtao on 17/1/5.
//  Copyright © 2017年 hanju001. All rights reserved.
//

import Foundation

extension String{
    
    /// 当前字符串中提取连接和文本
    /// Swift 提供元祖 同时返回多个值
    func zl_href() -> (link: String, text: String)? {
        
        let pattern = "<a href=\"(.*?)\".*?>(.*?)</a>"
        
        guard let regex = try? NSRegularExpression(pattern: pattern, options: []), let resgult = regex.firstMatch(in: self, options: [], range: NSRange(location: 0, length: characters.count)) else {
            
            return nil
        }
        let link = (self as NSString).substring(with: resgult.rangeAt(1))
        let text = (self as NSString).substring(with: resgult.rangeAt(2))
        
        return (link, text)
        
    }
    
}
